package com.zch.threaduse;

public class ThreadMethod01 {
    public static void main(String[] args) throws InterruptedException {
        T1 t = new T1();
        t.setName("zch");
        t.setPriority(Thread.MIN_PRIORITY); //1
        t.start(); //启动子线程

        //主线程 打印 5 个 hi ，然后中断
        for (int i = 0; i < 5; i++) {
            Thread.sleep(1000);
            System.out.println("hi  " + i);
        }

        System.out.println(t.getName() + " 线程的优先级 = " + t.getPriority()); //1
        t.interrupt();  //中断 t 线程休眠
    }
}

//自定义线程类
class T1 extends Thread{
    @Override
    public void run() {
        while (true){
            for (int i = 0; i < 3; i++) {
                System.out.println(Thread.currentThread().getName() + " 吃包子---" + i);
            }
            try {
                System.out.println(Thread.currentThread().getName() + "休眠中 --- ");
                Thread.sleep(20000); //2s
            } catch (InterruptedException e) {
                System.out.println(Thread.currentThread().getName() + "被 interrupt 了");
            }
        }
    }
}
